<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型</td>
                    <td><select v-model="a.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in xlk.list">{{ item.Name }}</option>
                        </select></td>
                </tr>
                <tr>
                    <td>房间号码</td>
                    <td><input type="text" v-model="a.HouseNumber"></td>
                </tr>
                <tr>
                    <td>房间描述</td>
                    <td><textarea v-model="a.DescHouse"></textarea></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td><input type="radio" name="state" v-model="a.State" :value="1">上架
                        <input type="radio" name="state" v-model="a.State" :value="0">下架
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>



<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
const router = useRouter();
const route = useRoute();

onMounted(() => {
    showtype();
})

let a: any = reactive({
    HouseTypeId: '',
    HouseNumber: '',
    DescHouse: '',
    State: 0
})




let xlk: any = reactive({
    list: [],
})

const ok: any = () => {
    if(a.HouseTypeId=="")
    {
        alert("不能为空");
        return;
    }
    axios({
        url: '/api/House/AddNumber',
        method: 'post',
        data: a
    })
        .then((res) => {
            if (res.data > 0) {
                alert("添加成功");
                router.push("/shownum")
            }
            else {
                alert("添加失败");
                return;
            }
        })
}

const showtype: any = () => {
    axios({
        url: 'api/House/ShowHouseType',
        method: 'get',
        params:{pageHang:100}
    })
        .then((res) => {
            xlk.list = res.data.list
        })
}
</script>

<style scoped></style>